package com.atstudy.headline.web.admin.service.impl;

import com.atstudy.headline.entity.AdCampaigns;
import com.atstudy.headline.web.admin.mapper.AdCampaignsMapper;
import com.atstudy.headline.web.admin.service.AdCampaignsService;
import com.atstudy.headline.web.admin.vo.ad.AdCampaignsVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* @author A
* @description 针对表【ad_campaigns(广告计划表)】的数据库操作Service实现
* @createDate 2025-06-12 13:55:56
*/
@Service
public class AdCampaignsServiceImpl extends ServiceImpl<AdCampaignsMapper, AdCampaigns>
    implements AdCampaignsService {

    @Override
    public IPage<AdCampaigns> pageInfoByAdCampaigns(IPage<AdCampaigns> page, AdCampaignsVo queryVo) {
        return baseMapper.pageInfoByAdCampaigns(page,queryVo);
    }

    @Override
    public List<Map<Integer, Object>> selectCampaigns() {
        return baseMapper.selectCampaigns();
    }


    public List<Integer> findCampaignIdsByAdvertiser(Integer advertiserId) {
        QueryWrapper<AdCampaigns> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("campaign_id")
                .eq("advertiser_id", advertiserId);
        return baseMapper.selectList(queryWrapper)
                .stream()
                .map(AdCampaigns::getCampaignId)
                .collect(Collectors.toList());
    }

    public void deleteByAdvertiserId(Integer advertiserId) {
        QueryWrapper<AdCampaigns> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("advertiser_id", advertiserId);
        baseMapper.delete(queryWrapper);
    }

}




